﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;

public partial class ManageCenter_UpdateDoc : System.Web.UI.Page
{
    Documents document = new Documents();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            panladddoc.Visible = false;
            panlupddoc.Visible = false;
            PageBind();
        }
    }
    protected void PageBind()
    {
        DataSet ds = document.GetAllDocumentsds();
        gvshowdoc.DataSource = ds;
        gvshowdoc.DataBind();
    }
    protected void btnadddoc_Click(object sender, EventArgs e)
    {
        panladddoc.Visible = true;
        panlupddoc.Visible = false;
    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        document.Doc_name=txbdocname.Text;
        document.Doc_type=ddltype.SelectedValue;
        document.Doc_remark=string.IsNullOrEmpty(txbremark.Text)?"":txbremark.Text;
        bool succ = document.AddNewDocument(document);
        if (succ)
            WebHelper.AlertAndRedirect("添加成功","UpdateDoc.aspx");
        else
            WebHelper.Alert("网络延时，请重新添加！");
    }
    protected void txbupdate_Click(object sender, EventArgs e)
    {
        document.Doc_id=Convert.ToInt32(lbldocid.Text);
        document.Doc_name = txbdocnameup.Text;
        document.Doc_type = ddltypeup.SelectedValue;
        document.Doc_remark = string.IsNullOrEmpty(txbremarkup.Text) ? "" : txbremarkup.Text;
        bool succ = document.UpdateADocument(document);
        if (succ)
            PageBind();
        else
            WebHelper.Alert("网络延时，请重新添加！");
    }
    protected void gvshowdoc_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "del")
        {
            int id=Convert.ToInt32(e.CommandArgument.ToString());
            bool succ = document.DeleteADocument(id);
            if (succ)
                Response.Redirect("UpdateDoc.aspx");
            else
                WebHelper.Alert("网络延时，请重新添加！");
        }
        if (e.CommandName.ToLower() == "upd")
        {
            panlupddoc.Visible = true;
            panladddoc.Visible = false;
            document=new Documents(Convert.ToInt32(e.CommandArgument.ToString()));
            if (document!=null)
            {
                txbdocnameup.Text = document.Doc_name;
                txbremarkup.Text = document.Doc_remark;
                ddltypeup.SelectedValue = document.Doc_type;
            }
            lbldocid.Text = e.CommandArgument.ToString();
        }
    }
    protected void gvshowdoc_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lkbtndel = (LinkButton)e.Row.FindControl("lkbtndel");
        if (lkbtndel != null)
            lkbtndel.Attributes.Add("onclick", "return confirm('确定要删除该证件材料吗？')");
    }
}
